const Promise = function(executor){
	if(!(executor instanceof Function)){
		throw "executor类型错误！"
	}
	this.state = "pending";// 状态
	this.result = undefined;// 状态值
	// 更改状态为fulfilled,成功值为value
	const _onResolve =function(value){
		// 如果状态被更改，那么不允许执行后续代码（状态只允许更改一次）
		if(this.state !== "pending") return;
		this.state = "fulfilled";
		this.result = value;
	}
	// 更改状态为rejected,失败的值为value
	const _onReject = function(value){
		if(this.state !== "pending") return;
		this.state = "rejected";
		this.result = value;
	}
	try{
		// 调用执行器函数
		executor(_onResolve.bind(this),_onReject.bind(this));
	}catch (value){
		// _onReject.bind(this,value)();
		_onReject.call(this,value)
	}
	
};
export default Promise;